dnd: Add gdk_drag_context_get_display()
authorBenjamin Otte <otte@redhat.com>
Tue, 5 Dec 2017 16:30:58 +0000 (17:30 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 10 Dec 2017 00:09:14 +0000 (01:09 +0100)
Also turn it into a readable, construct-only property.

Every GDK object should have this. (Apart from GdkDisplay, obviously.)

docs/reference/gdk/gdk4-sections.txt
gdk/broadway/gdkdnd-broadway.c
gdk/gdkdnd.c
gdk/gdkdnd.h
gdk/quartz/gdkdnd-quartz.c
gdk/wayland/gdkdnd-wayland.c
gdk/win32/gdkdnd-win32.c
gdk/x11/gdkdnd-x11.c

index 63b09bb198ba4d2eb3b92f46d02848c9a8d7d5b4..d167c2b7c633f09c5ce880e7db59b9778739bb42 100644 (file)
@@ -860,6 +860,7 @@ GdkDragAction
 gdk_drag_status
 gdk_drag_drop_succeeded
 
+gdk_drag_context_get_display
 gdk_drag_context_get_actions
 gdk_drag_context_get_suggested_action
 gdk_drag_context_get_selected_action
index 264da5e5f0cc3211bdb47f59767670836bba88ff..cbc1860181190d68d19857da3dff40dbc6e89fc6 100644 (file)
@@ -96,8 +96,8 @@ _gdk_broadway_window_drag_begin (GdkWindow         *window,
   g_return_val_if_fail (GDK_WINDOW_IS_BROADWAY (window), NULL);
 
   new_context = g_object_new (GDK_TYPE_BROADWAY_DRAG_CONTEXT,
+                              "display", gdk_window_get_display (window),
                              NULL);
-  new_context->display = gdk_window_get_display (window);
 
   return new_context;
 }
index 5bf0ab3aa5bb2c038cb87d540262d0adc71789ea..ead7bdfdb176b47bd046d34ca4d407a4e55ba0a1 100644 (file)
@@ -46,6 +46,12 @@ static struct {
   { 0,                  "dnd-none", NULL },
 };
 
+enum {
+  PROP_0,
+  PROP_DISPLAY,
+  N_PROPERTIES
+};
+
 enum {
   CANCEL,
   DROP_PERFORMED,
@@ -54,6 +60,7 @@ enum {
   N_SIGNALS
 };
 
+static GParamSpec *properties[N_PROPERTIES] = { NULL, };
 static guint signals[N_SIGNALS] = { 0 };
 static GList *contexts = NULL;
 
@@ -73,6 +80,20 @@ static GList *contexts = NULL;
  * the GTK+ documentation for more information.
  */
 
+/**
+ * gdk_drag_context_get_display:
+ * @context: a #GdkDragContext
+ *
+ * Gets the #GdkDisplay that the drag context was created for.
+ *
+ * Returns: (transfer none): a #GdkDisplay
+ **/
+GdkDisplay *
+gdk_drag_context_get_display (GdkDragContext *context)
+{
+  return context->display;
+}
+
 /**
  * gdk_drag_context_get_formats:
  * @context: a #GdkDragContext
@@ -230,6 +251,47 @@ gdk_drag_context_init (GdkDragContext *context)
   contexts = g_list_prepend (contexts, context);
 }
 
+static void
+gdk_drag_context_set_property (GObject      *gobject,
+                               guint         prop_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+  GdkDragContext *context = GDK_DRAG_CONTEXT (gobject);
+
+  switch (prop_id)
+    {
+    case PROP_DISPLAY:
+      context->display = g_value_get_object (value);
+      g_assert (context->display != NULL);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gdk_drag_context_get_property (GObject    *gobject,
+                               guint       prop_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  GdkDragContext *context = GDK_DRAG_CONTEXT (gobject);
+
+  switch (prop_id)
+    {
+    case PROP_DISPLAY:
+      g_value_set_object (value, context->display);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+      break;
+    }
+}
+
 static void
 gdk_drag_context_finalize (GObject *object)
 {
@@ -252,8 +314,27 @@ gdk_drag_context_class_init (GdkDragContextClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->get_property = gdk_drag_context_get_property;
+  object_class->set_property = gdk_drag_context_set_property;
   object_class->finalize = gdk_drag_context_finalize;
 
+  /**
+   * GdkDragContext:display:
+   *
+   * The #GdkDisplay that the drag context belongs to.
+   *
+   * Since: 3.94
+   */
+  properties[PROP_DISPLAY] =
+    g_param_spec_object ("display",
+                         "Display",
+                         "Display owning this clipboard",
+                         GDK_TYPE_DISPLAY,
+                         G_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY |
+                         G_PARAM_STATIC_STRINGS |
+                         G_PARAM_EXPLICIT_NOTIFY);
+
   /**
    * GdkDragContext::cancel:
    * @context: The object on which the signal is emitted
@@ -342,6 +423,8 @@ gdk_drag_context_class_init (GdkDragContextClass *klass)
                   NULL, NULL,
                   g_cclosure_marshal_VOID__FLAGS,
                   G_TYPE_NONE, 1, GDK_TYPE_DRAG_ACTION);
+
+  g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 }
 
 /*
index d7eac34d86a2135e202bc689f884c21c8c592ff9..85f8fa0a383b8d5b7fa227e45503279e445b1d5c 100644 (file)
@@ -83,6 +83,8 @@ typedef enum {
 GDK_AVAILABLE_IN_ALL
 GType            gdk_drag_context_get_type             (void) G_GNUC_CONST;
 
+GDK_AVAILABLE_IN_3_94
+GdkDisplay *     gdk_drag_context_get_display          (GdkDragContext *context);
 GDK_AVAILABLE_IN_ALL
 void             gdk_drag_context_set_device           (GdkDragContext *context,
                                                         GdkDevice      *device);
index ee187041e7a42170e218504c3b614bbe21032c19..fc9c338ca2dec3e4f2096ba996f2b291e31a2e30 100644 (file)
@@ -43,8 +43,8 @@ _gdk_quartz_window_drag_begin (GdkWindow *window,
 
   /* Create fake context */
   _gdk_quartz_drag_source_context = g_object_new (GDK_TYPE_QUARTZ_DRAG_CONTEXT,
+                                                  "display", display,
                                                   NULL);
-  _gdk_quartz_drag_source_context->display = gdk_window_get_display (window);
   _gdk_quartz_drag_source_context->is_source = TRUE;
 
   _gdk_quartz_drag_source_context->source_window = window;
index c676f258ccab5476d1cc65b6f5b3585b962e735b..a7281b82cc4d8eb986552071953c72edecfbd672 100644 (file)
@@ -513,9 +513,10 @@ _gdk_wayland_window_drag_begin (GdkWindow         *window,
   const char *const *mimetypes;
   gsize i, n_mimetypes;
 
-  context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT, NULL);
+  context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT,
+                                  "display", gdk_window_get_display (window),
+                                  NULL);
   context = GDK_DRAG_CONTEXT (context_wayland);
-  context->display = gdk_window_get_display (window);
   context->source_window = g_object_ref (window);
   context->is_source = TRUE;
   context->formats = gdk_content_formats_ref (formats);
@@ -544,9 +545,10 @@ _gdk_wayland_drop_context_new (GdkDisplay            *display,
   GdkWaylandDragContext *context_wayland;
   GdkDragContext *context;
 
-  context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT, NULL);
+  context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT,
+                                  "display", display,
+                                  NULL);
   context = GDK_DRAG_CONTEXT (context_wayland);
-  context->display = display;
   context->is_source = FALSE;
   context->formats = gdk_content_formats_new (NULL, 0);
 
index ea4deb056ed0681435a8a095619a50d4beb90499..fbf5af6922f0257b9b56fa60079e91d3d4a55a6b 100644 (file)
@@ -238,9 +238,10 @@ gdk_drag_context_new (GdkDisplay *display)
   GdkWin32Display *win32_display = GDK_WIN32_DISPLAY (display);
   GdkDragContext *context;
 
-  context_win32 = g_object_new (GDK_TYPE_WIN32_DRAG_CONTEXT, NULL);
+  context_win32 = g_object_new (GDK_TYPE_WIN32_DRAG_CONTEXT,
+                                "display", display,
+                                NULL);
   context = GDK_DRAG_CONTEXT(context_win32);
-  context->display = display;
 
   gdk_drag_context_set_device (context, gdk_seat_get_pointer (gdk_display_get_default_seat (display)));
 
index 5b3947eed1e0123cb04147b1d7ec2a8b48b1b6bc..85a98c50531b0c9fcebf926526d1486d850a3a3d 100644 (file)
@@ -1134,19 +1134,6 @@ send_client_message_async_cb (Window   window,
   g_object_unref (context);
 }
 
-
-static GdkDisplay *
-gdk_drag_context_get_display (GdkDragContext *context)
-{
-  if (context->source_window)
-    return GDK_WINDOW_DISPLAY (context->source_window);
-  else if (context->dest_window)
-    return GDK_WINDOW_DISPLAY (context->dest_window);
-
-  g_assert_not_reached ();
-  return NULL;
-}
-
 static void
 send_client_message_async (GdkDragContext      *context,
                            Window               window,
@@ -1672,10 +1659,11 @@ xdnd_enter_filter (GdkXEvent *xev,
       display_x11->current_dest_drag = NULL;
     }
 
-  context_x11 = (GdkX11DragContext *)g_object_new (GDK_TYPE_X11_DRAG_CONTEXT, NULL);
+  context_x11 = g_object_new (GDK_TYPE_X11_DRAG_CONTEXT,
+                              "display", display,
+                              NULL);
   context = (GdkDragContext *)context_x11;
 
-  context->display = display;
   context->protocol = GDK_DRAG_PROTO_XDND;
   context_x11->version = version;
 
@@ -1984,9 +1972,10 @@ _gdk_x11_window_drag_begin (GdkWindow         *window,
 {
   GdkDragContext *context;
 
-  context = (GdkDragContext *) g_object_new (GDK_TYPE_X11_DRAG_CONTEXT, NULL);
+  context = (GdkDragContext *) g_object_new (GDK_TYPE_X11_DRAG_CONTEXT,
+                                             "display", gdk_window_get_display (window),
+                                             NULL);
 
-  context->display = gdk_window_get_display (window);
   context->is_source = TRUE;
   context->source_window = window;
   g_object_ref (window);